﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ClassLibrary
{
    public enum LogLevel
    {
        DEBUG = 0,
        LOG = 1,
        EXCEPTION = 2
    }

    public partial class LogWriter
    {
        private LogWriter()
        {
        }

        #region Print() Overload functions
        public static void Print(string message, LogLevel severity, string file)
        {
            try
            {
                file = (file == null ? System.Configuration.ConfigurationManager.AppSettings["LogServer"] : file);
                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(file, true))
                {
                    string entry = "[" + DateTime.Now.ToString() + "] [" + Enum.GetName(typeof(LogLevel), severity) + "]" + Environment.NewLine + message + Environment.NewLine;
                    sw.WriteLine(entry);
                }
            }
            catch (Exception exc)
            {
                Console.Error.WriteLine("[Exception when writing to logfile] " + exc);
            }
        }

        public static void Print(string message, LogLevel severity)
        {
            Print(message, severity, null);
        }
        public static void Print(Exception exception, LogLevel severity)
        {
            Print(exception.ToString(), severity, null);
        }
        #endregion
    }
}

/*
string entry = "<span style=\"font-family:monospace;\">[" +
                                        DateTime.Now.ToString() + "] [" + Enum.GetName(typeof(LogLevel), severity) + "] <br \\>" + exception.to +
                                    "</span><br \\>";
*/